#light
open System

let invar = Globalization.CultureInfo.InvariantCulture
let style = Globalization.DateTimeStyles.None

let (|ParseIsoDate|_|) str =
    let res,date = DateTime.TryParseExact(str, "yyy-MM-dd", invar, style)
    if res then Some date else None

let (|ParseAmericanDate|_|) str =
    let res,date = DateTime.TryParseExact(str, "MM-dd-yyyy", invar, style)
    if res then Some date else None
    
let (|Parse3LetterMonthDate|_|) str =
    let res,date = DateTime.TryParseExact(str, "MMM-dd-yyyy", invar, style)
    if res then Some date else None
    
let parseDate str =
    match str with
    | ParseIsoDate d -> d
    | ParseAmericanDate d -> d
    | Parse3LetterMonthDate d -> d
    | _ -> failwith "unrecognized date format"

(*
parseDate "05-23-1978"
parseDate "May-23-1978"
parseDate "1978-05-23"
parseDate "05-23-78"
*)